package com.ptszyxx.popose.module.main.mine.vm;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ptszyxx.popose.common.event.ShopEvent;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.RxBus;
import com.ysg.bus.RxSubscriptions;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.data.CommonRepository;
import com.ysg.utils.YStringUtil;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class MineShopMyVM extends BaseViewModel<CommonRepository> {

    public MineShopMyVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onPicEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onCloseCommand = new BindingCommand(()-> YActivityUtil.getInstance().close(this));
    public BindingCommand onRightCommand = new BindingCommand(()-> YActivityUtil.getInstance().jumpMineShopMy(this));

    public Disposable disposable;
    @Override
    public void registerRxBus() {
        super.registerRxBus();
        disposable = RxBus.getDefault().toObservable(ShopEvent.class)
                .subscribe(new Consumer<ShopEvent>() {
                    @Override
                    public void accept(ShopEvent event){
                        if (event != null && YStringUtil.eq(2, event.getType())){
                            uc.onPicEvent.setValue(event.getUrl());
                        }
                    }
                });
    }

    @Override
    public void removeRxBus() {
        super.removeRxBus();
        RxSubscriptions.remove(disposable);
    }
    //=========================================接口：start===========================================

}
